package com.banmao.algorithm.No101To200.No145;

import java.util.ArrayList;
import java.util.List;

public class Solution1 {

    public List<Integer> postorderTraversal(TreeNode root) {
        ArrayList<Integer> list = new ArrayList<Integer>();

        traversal(root, list);

        return list;


    }

    private void traversal(TreeNode root, List<Integer> list) {
        if(root == null) {
            return;
        }
        traversal(root.left, list);
        traversal(root.right, list);
        list.add(root.val);

    }

}


class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;
    TreeNode() {}
    TreeNode(int val) { this.val = val; }
    TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}